/*
 * CreepSprintingSalmon.java
 *
 * Created on January 4, 2008, 1:11 PM
 *
 * Copyright (C) 2007-2008  Hylke van der Schaaf
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, in version 3 of the License.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */
package hextd.creep;

import hextd.Constants.COLOR;
import hextd.util.Cache;
import java.awt.Color;
import java.awt.Shape;
import java.awt.Stroke;
import com.usoog.tdcore.gamegrid.ScaledCanvas;
import com.usoog.tdcore.gamestate.GameState;

/**
 *
 * @author hylke
 */
public class CreepSprintingSalmon extends CreepBaseDirectional {

	public static String type = "ss";
	//
	private int energy = 80;
	private int energyMax = 80;
	private long oldHealth;
	private boolean sprinting = false;
	private boolean recharging = false;
	private double oldSpeed;
	private double oldPower;
	private String infoText = "<h1>Sprinting Salmon</h1>"
			+ "<p>"
			+ "If a Sprinting Salmon takes damage, it tries to sprint out of harms way."
			+ "</p>";

	/** Creates a new instance of CreepSprintingSalmon */
	public CreepSprintingSalmon() {
		super("Sprinting Salmon", true);
		this.damageColor = COLOR.OTHER;
		this.damageColorAnti = COLOR.OTHER;
	}

	@Override
	public String getType() {
		return type;
	}

	@Override
	public void init(GameState gs, HexTDCreepData data) {
		super.init(gs, data);
		oldHealth = health;
		oldSpeed = this.getSpeedMaxBase();
		oldPower = this.getPowerBase();
	}

	@Override
	public void resetScale(ScaledCanvas sc) {
		Cache.getInstance().loadSvg("ss", "images/image2.svg");
		super.resetScale(sc);
	}

	@Override
	public String getInfoString() {
		return this.infoText
				+ "<p>" + super.getInfoString() + "</p>";
	}

	@Override
	public void doTick(int gameTime) {
		if (!sprinting && !recharging) {
			if (health < oldHealth) {
				sprinting = true;
				speedMaxBase = oldSpeed * 2;
				speedMax *= 2;
				powerBase = oldPower * 2;
				power *= 2;
				speed = speedMax;
			}
		}
		if (recharging) {
			energy++;
			if (energy >= energyMax) {
				recharging = false;
			}
		}
		if (sprinting) {
			energy -= 2;
			if (energy <= 0) {
				sprinting = false;
				recharging = true;
				speedMaxBase = oldSpeed;
				powerBase = oldPower;
				speedMax /= 2;
				power /= 2;
				if (speedMax > getSpeedMaxBase()) {
					speedMax = getSpeedMaxBase();
				}
				if (power > getPowerBase()) {
					power = getPowerBase();
				}
			}
		}
		super.doTick(gameTime);
		oldHealth = health;
	}

	@Override
	Color generateColor() {
		return null;
	}

	@Override
	Stroke generateStroke() {
		return null;
	}

	@Override
	Shape[] generateShapes() {
		return null;
	}

	@Override
	String getSvgName() {
		return "ss";
	}
}
